package db.pojo;

import java.util.*;
import java.text.SimpleDateFormat;
import db.ext.StudentExt;
@SuppressWarnings("unchecked")
/**
 * student
 */
public class Student {
	/**
	 * id
	 */
	public int id;
	/**
	 * name
	 */
	public String name;
	/**
	 * sexId
	 */
	public int sexId;
	/**
	 * beginDate
	 */
	public java.util.Date beginDate;
	/**
	 * goodStudent
	 */
	public boolean goodStudent;
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static StudentExt DB = new StudentExt(); 
	
	public Student() {
		super();
	}
	
	public Student(int id, String name, int sexId, java.util.Date beginDate, boolean goodStudent) {
		super();
		this.id = id; 
		this.name = name; 
		this.sexId = sexId; 
		this.beginDate = beginDate; 
		this.goodStudent = goodStudent; 
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	} 
	
	public void changeIdWith(int id){
		this.id += id;
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
	}	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	} 
	
	public int getSexId() {
		return sexId;
	}

	public void setSexId(int sexId) {
		this.sexId = sexId;
	} 
	
	public void changeSexIdWith(int sexId){
		this.sexId += sexId;
	}
	
	public void changeSexIdWithMin(int sexId,int min){
		this.sexId += sexId;
		this.sexId = this.sexId < min ? min : this.sexId;
	}
	
	public void changeSexIdWithMax(int sexId,int max){
		this.sexId += sexId;
		this.sexId = this.sexId > max ? max : this.sexId;
	}
	
	public void changeSexIdWithMaxMin(int sexId,int max,int min){
		this.sexId += sexId;
		this.sexId = this.sexId < min ? min : this.sexId;
		this.sexId = this.sexId > max ? max : this.sexId;
	}	
	public java.util.Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(java.util.Date beginDate) {
		this.beginDate = beginDate;
	} 
	
	public boolean getGoodStudent() {
		return goodStudent;
	}

	public void setGoodStudent(boolean goodStudent) {
		this.goodStudent = goodStudent;
	} 
	
	
	public Map studentToMap() {
		Map map = new HashMap();
		try {
			map.put("id",this.id);
			map.put("name",this.name);
			map.put("sexId",this.sexId);
			map.put("beginDate",simpleDateFormat.format(this.beginDate));
			map.put("goodStudent",this.goodStudent);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	public Student mapToStudent(Map map){
		try {
			int id = Integer.parseInt( map.get("id").toString());
			String name =  map.get("name").toString();
			int sexId = Integer.parseInt( map.get("sexId").toString());
			java.util.Date beginDate = simpleDateFormat.parse( map.get("beginDate").toString());
			boolean goodStudent = Boolean.parseBoolean( map.get("goodStudent").toString());
			Student student = new Student(id, name, sexId, beginDate, goodStudent);
			return student;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	} 
	
	public String toString(){
		return studentToMap().toString();
	}
	
	//方便数据操作	
	public Student insert(){
		return DB.insert(this);
	}
	public Student update(){
		return DB.update(this);
	}
	
	public int delete(){
		return DB.delete(this);
	}
	
	
	public Sex getFk_Sex_SexId(){
		return DB.getFk_Sex_SexId(this);
	}
	
}
